<?php
   class Model_car extends CI_Model{
		protected $_table = "tbl_car";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function getdata($id){
			$this->db->where("id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function listall($limit,$start){
			$this->db->limit($limit,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function add($data){
        	$this->db->insert($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			$this->db->delete($this->_table);
		}
		public function update($data,$id){
			$this->db->where("id",$id);
			$this->db->update($this->_table,$data);
		}
		
		public function listallby_search($provide,$pickup,$service,$limit,$start){
			$query=$this->db->query("select * from tbl_car where provide like '%".$provide."%' and pickup like '%".$pickup."%' and service like '%".$service."%' order by price limit ".$start.",".$limit);	
			//var_dump("select * from tbl_car where provide like '%".$provide."%' and pickup like '%".$pickup."%' and service like '%".$service."%' order by price limit ".$start.",".$limit);
			return $query->result_array();
		}
		
		public function count_search(){
			$query=$this->db->query("select count(*) as total from tbl_car");	
			return $query->row_array();
		}
		
		public function gettopByprovide_status($provide,$status,$limit,$start){
			$query=$this->db->query("select * from tbl_car where provide like '%".$provide."%' and status=".$status." order by id limit ".$start.",".$limit);	
			return $query->result_array();
		}
		
		//admin
		public function getallbyprovide_name($provide,$name){
			$select="select * from tbl_car";
			$where=" where 1=1 ";
			$order=" order by name";
			if($provide!='0') $where.=" and provide like '%".$provide."%' ";
			if($name!='') $where.=" and name like '%".$name."%' ";
			$query=$this->db->query($select.$where.$order);
			return $query->result_array();
		}
	}
	?>